package com.personnel.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.personnel.dao.ILzUserDao;
import com.personnel.dao.LzUserDao;
import com.personnel.entity.LzUser;
import com.personnel.entity.YgPage;
import com.personnel.service.ILzUserService;
import com.personnel.service.IYgUserService;
import com.personnel.service.LzUserService;
import com.personnel.service.YgUserService;

/**
 * Servlet implementation class ListLzUserServlet
 */
@WebServlet("/lz.do")
public class ListLzUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListLzUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		IYgUserService service = new YgUserService();
		ILzUserDao dao = new LzUserDao();
		int cunrrentPage = 1;
		int count = 10;
		
		String value = request.getParameter("page");
		if(value != null && !"".equals(value)) {
			cunrrentPage = Integer.parseInt(value);
		}
		YgPage page = service.findPage(cunrrentPage, count);
		
		System.out.println(page);
		
		request.setAttribute("page", page);
		
		List<LzUser> data;
		try {
			data = dao.queryAllLzUsers();
			System.out.println(data);
			
			request.setAttribute("data", data);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			
		
		
		
		request.getRequestDispatcher("module2/personout.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
